<?php

defined('IN_PHPCMS') or exit('No permission resources.');
//模型缓存路径
define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);

pc_base::load_app_class('admin', 'admin', 0);
pc_base::load_sys_class('format', '', 0);
pc_base::load_sys_class('form', '', 0);
pc_base::load_app_func('util', 'content');
class upfiles{
    public $upfile = "uploadfile/users/"; //上传目录
  
    public $maxsize= 1024000;
    //上传方法开始
    function upfile($filename){
        $newname = date("Ymdhs").mt_rand(0,9).mt_rand(0,9).mt_rand(0,9); //使用日期做文件名
	
        $name = $_FILES[$filename]["name"];
		$type = $_FILES[$filename]["type"];
		$size = $_FILES[$filename]["size"];
		$tmp_name = $_FILES[$filename]["tmp_name"];
      
        //文件类型判断
        switch ($type) {
			case 'image/pjpeg' :
			case 'image/jpeg' :
				$extend = ".jpg";
				break;
			case 'image/gif' :
				$extend = ".gif";
				break;
			case 'image/png' :
				$extend = ".png";
				break;
		}
        
      
        $filename=$newname.$extend;
        if (move_uploaded_file($tmp_name, $this->upfile.$filename)) {
			return $filename;
		}
    }
}
    
    //上传方法完成

class caswee_admin{
	
	private $db, $verify_db;
	
	function __construct() {
		
	
		$this->_username = param::get_cookie('_username');
		$this->caswee_db = pc_base::load_model('caswee_model');
		$this->casweeproduct_db = pc_base::load_model('caswee_product');
pc_base::load_app_func('global');
	}
	public function init() {
		pc_base::load_sys_class('form', '', 0);
		$_username = $this->_username;
		if(!$_username)
			showmessage(L('请登录后再进行操作！'),'index.php?m=member&c=index&a=login');
		 $style=$_GET['style'];
	  $where=isset($_GET['style'])?"class1='$style'":null;
	$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
		$infos = $this->caswee_db->listinfo($where,$order = 'id DESC',$page, $pages = '9');
		$infos2 = $this->casweeproduct_db->listinfo($where1,$order = 'id DESC',$page, $pages = '15');
		$pages = $this->caswee_db->pages;
		$pages = $this->casweeproduct_db->pages;
			$action=$_GET["action"];
			$template=caswee_admin.$action;
		
		include template('caswee',$template);
	}
		
	
		
		public function ly(){
 	
			
			
			$img= new upfiles();   //实例化类文件
            $photo = $img->upfile("file"); //上传的文件域
 if ($photo){
$_POST['ly']['addtime'] =time();
 			$_POST['ly']['userid'] = $this->_userid;
 			$_POST['ly']['username'] = $this->_username;
 			$_POST['ly']['title'] = $_POST['title'];
			$_POST['ly']['content'] = $_POST['editor1'];
			$_POST['ly']['class1']=$_POST['class1'];
			$_POST['ly']['img'] = $photo;
			$_POST['ly']['lang']=$_POST['class2'];
 			
  			$this->caswee_db->insert($_POST['ly']);
 			showmessage(L('add_success'), "?m=caswee&c=mycaswee_admin");
 		
 
 			
 }else{
 showmessage(L('无图片内容'), "?m=caswee&c=caswee_admin&action=add");
	 }

		}
			public function la(){

 			$_POST['la']['id'] = $_POST['id'];
			
			$_POST['la']['class1']=$_POST['class1'];
			$_POST['la']['lang']=$_POST['class'];
		$_POST['la']['link'] =$_POST['link'];
 			
  			$this->casweeproduct_db->insert($_POST['la']);
 			showmessage(L('add_success'), "?m=caswee&c=caswee_admin&action=class");
 		
 
 			
 }
 public function lb(){
 	
		
 		
 		$id=$_POST['id'];
 			$_POST['ly']['class1'] =$_POST['class1'];
			$_POST['ly']['link'] =$_POST['link'];
			
			
 			
  			$this->casweeproduct_db->update($_POST['ly'],"id=$id");
 			showmessage(L('add_success'), "?m=caswee&c=caswee_admin&action=class");
 		
 
 			
 
	}
	 public function lc(){
 	
		$img1= new upfiles();   //实例化类文件
            $photo1 = $img1->upfile("file2"); //上传的文件域
 		
 		$id=$_POST['id'];
 			$_POST['ly']['title'] =$_POST['title'];
		
			$_POST['ly']['content'] =$_POST['content'];
			$_POST['ly']['class1'] =$_POST['class1'];
			
			if(!$photo1){
 		$_POST['ly']['img']=$_POST['tupian'];
			}else{
				$_POST['ly']['img']=$photo1;}
 			
  			$this->caswee_db->update($_POST['ly'],"id=$id");
 			showmessage(L('add_success'), "?m=caswee&c=caswee_admin&action=manage");
 		
 
 			
 
	}
public function delete(){
		$id=$_GET['id'];
		  	$_username=$this->_username;
	if(!$_username){
			showmessage(L('请登录后再进行操作！'),'index.php?m=member&c=index&a=login');
		}
			$this->caswee_db->delete(array('id'=>$id));
			showmessage(L('删除成功！'),'index.php?m=caswee&c=caswee_admin&action=manage');


	}
	public function delete1(){
		$id=$_GET['id'];
		  	$_username=$this->_username;
	if(!$_username){
			showmessage(L('请登录后再进行操作！'),'index.php?m=member&c=index&a=login');
		}
			$this->casweeproduct_db->delete(array('id'=>$id));
			showmessage(L('删除成功！'),'index.php?m=caswee&c=caswee_admin&action=class');


	}

	
}

?>